package stream;


import java.util.ArrayList;
import java.util.List;

public class StreamTest3 {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student("至尊宝", 26, 178));
        students.add(new Student("牛魔王", 33, 175));
        students.add(new Student("蜘蛛精", 22, 160));
        students.add(new Student("蜘蛛精", 22, 160));
        students.add(new Student("白晶晶", 24, 167));
        students.add(new Student("紫霞", 25, 173));
        // 找出年龄大于23切小于30的，降序排列
        students.stream().filter(s -> s.getAge() >= 23 && s.getAge() <= 30)
                .sorted((o1, o2) -> o2.getAge() - o1.getAge())
                .forEach(System.out::println);
        System.out.println("--------------------------------------");
        // 找出身高前三的学生
        students.stream().sorted((o1, o2) -> Double.compare(o2.getHeight(),o1.getHeight()))
                .limit(3).forEach(System.out::println);
        System.out.println("--------------------------------------");
        // 找出身高最低的两名学生
        students.stream().sorted((o1, o2) -> Double.compare(o2.getHeight(),o1.getHeight())).distinct()
                .skip(students.size() - 2).forEach(System.out::println);
        System.out.println("--------------------------------------");


    }
}
